package com.sh.data.engine.application.service.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sh.data.engine.common.util.ServletUtils;
import com.sh.data.engine.domain.api.model.domain.DataApiSecurityManageDomain;
import com.sh.data.engine.domain.api.service.DataApiSecurityManageService;
import com.sh.data.engine.domain.base.model.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: mengzheng.mhc
 * @date: 2024/8/16 10:29
 */
@Slf4j
@Service
public class DataApiSecurityManageApplicationService {

    @Autowired
    private DataApiSecurityManageService dataApiSecurityManageService;

    public PageResult<DataApiSecurityManageDomain> getApiSecurityManagePage(
        String apiName, Integer pageNum, Integer pageSize) {
        Long projectId = ServletUtils.getProjectId();
        IPage<DataApiSecurityManageDomain> apiSecurityManagePage =
            dataApiSecurityManageService.getApiSecurityManagePage(
                apiName, projectId, pageNum, pageSize);

        return PageResult.copyPropertiesAndConvert(
            apiSecurityManagePage, DataApiSecurityManageDomain.class);
    }

    public PageResult<DataApiSecurityManageDomain> getEditApiSecurityManagePage(
        Long apiId, String username, Integer pageNum, Integer pageSize) {
        Long projectId = ServletUtils.getProjectId();
        IPage<DataApiSecurityManageDomain> apiSecurityManageList =
            dataApiSecurityManageService.getApiSecurityManagePage(
                projectId, apiId, username, pageNum, pageSize);

        return PageResult.copyPropertiesAndConvert(
            apiSecurityManageList, DataApiSecurityManageDomain.class);
    }

    public boolean cancelApiSecurityManageById(String userId, Long apiId) {
        Long projectId = ServletUtils.getProjectId();
        return dataApiSecurityManageService.cancelApiSecurityManageById(projectId, userId, apiId);
    }
}
